/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package transactions;

import item.Item;
import java.sql.Date;
import myJPA.Model;
import user.Customer;
import user.Employee;
import javax.persistence.*;

/**
 *
 * @author ZIZI
 */
@Entity
@Table(name="rental")
@NamedQueries({
@NamedQuery(name="findRentalBycustomerAndItem", query="select r from Rental r where r.customer = :cus AND r.item=:item and r.returned=false"),
@NamedQuery(name="findRentalByItem", query="select a from Rental a where a.item=:item "),
@NamedQuery(name="findRental", query="select r from Rental r where r.returned=false and dateReturn < :today"),        
@NamedQuery(name="findRental1", query="select r from Rental r where r.customer = :cus AND r.item=:item and r.returned=false")  
})
public class Rental extends Model{
    @Id
    @GeneratedValue
    private int id;
    private Date dateRental; 
    private Date dateReturn;
    
    private boolean returned;
    @ManyToOne
    @JoinColumn(name = "cus_id")
    private Customer customer; 
    
    @ManyToOne
    @JoinColumn(name = "item_id")
    private Item item; 
    
    @ManyToOne
    @JoinColumn(name = "emp_id")
    private Employee employee;

    public Rental() {
        super();
    }

    public Rental(Date dateRental, Date dateReturn, Customer customer, Item item, Employee employee) {
        super();
        this.dateRental = dateRental;
        this.dateReturn = dateReturn;
        this.customer = customer;
        this.item = item;
        this.employee = employee;
        this.returned = false;
    }
    
    public Rental(Date dateRental, Date dateReturn, Customer customer, Item item, Employee employee, boolean returned) {
        super();
        this.dateRental = dateRental;
        this.dateReturn = dateReturn;
        this.customer = customer;
        this.item = item;
        this.employee = employee;
        this.returned = returned;
    }

    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @return the dateRental
     */
    public Date getDateRental() {
        return dateRental;
    }

    /**
     * @param dateRental the dateRental to set
     */
    public void setDateRental(Date dateRental) {
        this.dateRental = dateRental;
    }

    /**
     * @return the dateReturn
     */
    public Date getDateReturn() {
        return dateReturn;
    }

    /**
     * @param dateReturn the dateReturn to set
     */
    public void setDateReturn(Date dateReturn) {
        this.dateReturn = dateReturn;
    }

    /**
     * @return the customer
     */
    public Customer getCustomer() {
        return customer;
    }

    /**
     * @param customer the customer to set
     */
    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    /**
     * @return the item
     */
    public Item getItem() {
        return item;
    }

    /**
     * @param item the item to set
     */
    public void setItem(Item item) {
        this.item = item;
    }

    /**
     * @return the employee
     */
    public Employee getEmployee() {
        return employee;
    }

    /**
     * @param employee the employee to set
     */
    public void setEmployee(Employee employee) {
        this.employee = employee;
    }

    public void setReturned(boolean returned) {
        this.returned = returned;
    }

    public boolean isReturned() {
        return returned;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Rental other = (Rental) obj;
        if (this.id != other.id) {
            return false;
        }
        if (this.dateRental != other.dateRental && (this.dateRental == null || !this.dateRental.equals(other.dateRental))) {
            return false;
        }
        if (this.dateReturn != other.dateReturn && (this.dateReturn == null || !this.dateReturn.equals(other.dateReturn))) {
            return false;
        }
        if (this.returned != other.returned) {
            return false;
        }
        if (this.customer != other.customer && (this.customer == null || !this.customer.equals(other.customer))) {
            return false;
        }
        if (this.item != other.item && (this.item == null || !this.item.equals(other.item))) {
            return false;
        }
        if (this.employee != other.employee && (this.employee == null || !this.employee.equals(other.employee))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        return hash;
    }

 
    
    
    

}
